package main

import "fmt"

func main() {
	//定义一个数组
	arr := []int{1, 2, 5, 7, 15, 25, 30, 36, 39, 51, 67, 78, 80, 82, 85, 91, 92, 97}
	BinaryFind(&arr, 0, len(arr)-1, 30)
	fmt.Println("main arr=", arr)
}

func BinaryFind(arr *[]int, leftIndex int, rightIndex int, findVal int) {
	//判断 leftIndex 是否大于rightIndex
	if leftIndex > rightIndex {
		fmt.Println("到不到")
		return
	}
	//先找到 中间的下标
	middle := (leftIndex + rightIndex) / 2
	if (*arr)[middle] > findVal {
		BinaryFind(arr, leftIndex, middle - 1, findVal)
	}else if (*arr)[middle] < findVal {
		BinaryFind(arr, middle+1, rightIndex, findVal)
	}else{
		fmt.Printf("找到了,下标为: %v\n", middle)
	}
}
